﻿using LeEdu.DTO;
using LeEdu.Service;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.Mvc;

namespace LeEdu.UI.Controllers
{
    public class HomeController : Controller
    {
        private InstallService installService;
        private CourseService courseService;
        private FileService fileService;
        private HourService hourService;


        public HomeController()
        {
            installService = new InstallService();
            courseService = new CourseService();
            fileService = new FileService();
            hourService = new HourService();
        }
        public ActionResult Index()
        {
            return RedirectToAction("Course") ;
        }

        public ActionResult About()
        {
            ViewBag.Message = "Your application description page.";

            return View();
        }

        public ActionResult Contact()
        {
            ViewBag.Message = "Your contact page.";

            return View();
        }

        /// <summary>
        /// 课程
        /// </summary>
        /// <returns></returns>
        public ActionResult Course()
        {           
            var courses = courseService.GetCoursesList();
            ViewBag.Courses = courses; 
            return View();
        }

        public ActionResult StudyCourse(Guid cid)
        {
            Course course = courseService.GetCourseById(cid);
            ViewBag.CourseName = course.Name;
            var hours = hourService.GetNodeList(cid);
            ViewBag.Hours = hours;
            ViewBag.CourseId = cid;//课程Id
            var files = fileService.SelectListByCourseIdAndDocType(cid);
            ViewBag.Files = files;
            return View();
        }

        public JsonResult StartVideo(Guid hid)
        {
            Hour hour = hourService.GetHourById(hid);
            return Json(hour.VideoUrl);
        }

    }
}